using System;
using System.Web.Mvc;
using System.Web.Routing;
using BrettM.Web.Hosting;
using BrettM.Web.Restful;
using Microsoft.Practices.Unity;

namespace BrettM.BootStrappers
{
    public class RestfulRoutesBootStrapper
        : IBootStrapper
    {
        public void OnStart(IUnityContainer container, PropertyBag bag)
        {

            var routes = RouteTable.Routes;

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            foreach (var controller in container.ResolveAll<IRestController>())
            {
                routes.MapRoute(controller);
            }


            routes.MapRoute(
                "NotFound",                                                  // Route name
                "{*id}",                                                     // URL with parameters
                new { controller = "Error", action = "NotFound", id = "" },  // Parameter defaults
                new string[] { typeof(ErrorController).Namespace }
            );
        }


        public void OnStop(IUnityContainer container, PropertyBag bag)
        {

        }

        public void Dispose()
        {
        }
    }
}
